package com.atguigu.edu.service.impl;

import com.atguigu.edu.dto.TeacherQueryDTO;
import com.atguigu.edu.entity.Teacher;
import com.atguigu.edu.mapper.TeacherMapper;
import com.atguigu.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author zhangsj
 * @since 2020-07-01
 */
@Service
@Slf4j
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Override
    public void pageQuery(Page<Teacher> page, TeacherQueryDTO dto) {
        log.info("分页查询讲师列表：{}", dto);
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort");

        if (dto != null) {
            if (StringUtils.isNotBlank(dto.getName())) {
                queryWrapper.like("name", dto.getName());
            }
            if (dto.getLevel() != null) {
                queryWrapper.eq("level", dto.getLevel());
            }
            if (StringUtils.isNotBlank(dto.getBegin())) {
                queryWrapper.like("name", dto.getBegin());
            }
            if (StringUtils.isNotBlank(dto.getEnd())) {
                queryWrapper.like("name", dto.getEnd());
            }
        }

        baseMapper.selectPage(page, queryWrapper);
    }
}
